package com.mrjy.schooldiy.controller;

import java.util.HashMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.DiyArticleInfo;
import com.mrjy.common.entity.DiyNoticeInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.enums.ResultEnum;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.schooldiy.bo.IDiyArticle;

@Controller
@RequestMapping("/schooldiy/article")
public class DiyArticleInfoController {
	@Resource
	private IDiyArticle schoolArticleBo;
	@RequestMapping("/insertDiyArticle")
	@ResponseBody
	public Object insertDiyNotice(DiyArticleInfo articleInfo,HttpSession session){
		return schoolArticleBo.insertDiyArticle(articleInfo,session);
	}
	
	@RequestMapping("/updateDiyArticle")
	@ResponseBody
	public Object updateDiyNotice(DiyArticleInfo articleInfo,HttpSession session){
		return schoolArticleBo.updateDiyArticle(articleInfo,session);
	}
	
	/**
	 * 禁用、起用
	 * @param ids
	 * @return
	 */
	@RequestMapping("/updateDisableFlag")
	@ResponseBody
	public Object updateDisableFlag(DiyArticleInfo articleInfo,HttpSession session) {	
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		HashMap<String, Object> map = new HashMap<String, Object>();
		if(null == loginUser ){
			map.put("err_msg", "用户未登录");
			map.put("err_code", -1);
			return map;
		}
		if (null == articleInfo.getIds()) {
			map.put("err_msg", ResultEnum.PARAM_ERROR);
			return map;
		}
		return schoolArticleBo.txUpdateDisableFlag(articleInfo);
    }
	/*
	 *Pc分页查询 
	 */
	@RequestMapping("/queryPageForPc")
	@ResponseBody
	public Object queryPageForPc(DiyArticleInfo articleInfo,HttpSession session) {	
		return schoolArticleBo.queryPageForPc(articleInfo,session);
    }
	
	/*
	 *微信端分页查询 
	 */
	@RequestMapping("/queryPageList")
	@ResponseBody
	public Object queryPageList(DiyArticleInfo articleInfo,HttpSession session) {	
		return schoolArticleBo.queryPageList(articleInfo,session);
    }
	
	/*
	 *微信端查询 推荐阅读详情
	 */
	@RequestMapping("/queryArticleById")
	@ResponseBody
	public Object queryArticleById(DiyArticleInfo articleInfo,HttpSession session) {	
		return schoolArticleBo.queryArticleById(articleInfo,session);
    }
	/*
	 *微信端推荐阅读详情浏览量+1
	 */
	@RequestMapping("/addArticleViewNum")
	@ResponseBody
	public Object addArticleViewNum(DiyArticleInfo articleInfo,HttpSession session) {	
		return schoolArticleBo.addArticleViewNum(articleInfo,session);
    }
}
